home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 2 / Mac Magazin and MacEasy Magazine CD - Issue 02.iso / Sharewarebibliothek / Applikationen / Alpha.5.81 folder / Tcl / SystemCode / grep.tcl < prev    next >
Text File  |  1994-05-31  |  2KB  |  64 lines

  1. #================================================================================
  2. # 'greplist' and 'grepfset' are used for batch searching from the "find" dialog.
  3. #  Hence, you really shouldn't mess with them unless you know what you are doing.
  4. #================================================================================
  5. proc greplist {args} {
  6.     set num [expr [llength $args] - 2]
  7.     set exp [lindex $args $num]
  8.     set arglist [lindex $args [expr $num + 1]]
  9.     
  10.     set owin 0
  11.     set cid [scancontext create]
  12.  
  13.     set cmd [lrange $args 0 [expr $num - 1]]
  14.     eval scanmatch $cmd {$cid $exp {
  15.             if (!$owin) {
  16.                 set owin 1
  17.                 new
  18.                 set w [lindex [winNames -f] 0]
  19.             }
  20.             insertText -w $w "File \"[file tail $f]\"; Line $matchInfo(linenum): $matchInfo(line)\r"}
  21.     }
  22.  
  23.     foreach f $arglist {
  24.         set fid [open $f]
  25.         scanfile $cid $fid
  26.         close $fid
  27.     }
  28.     scancontext delete $cid
  29. }
  30.  
  31. proc grepfset {args} {
  32.     global fileSets
  33.  
  34.     set num [expr [llength $args] - 2]
  35.     set exp [lindex $args $num]
  36.     set fset [lindex $args [expr $num + 1]]
  37.     eval greplist [lrange $args 0 [expr $num-1]] {$exp $fileSets($fset)}
  38. }
  39.  
  40. proc grep {exp args} {
  41.     set files {}
  42.     foreach arg $args {
  43.         if {![catch {glob -t TEXT $arg} lst]} {
  44.             append files " " $lst
  45.         }
  46.         if {![catch {glob -t ttro $arg} lst]} {
  47.             append files " " $lst
  48.         }
  49.     }
  50.     if {$files==""} {return $lst}
  51.     set cid [scancontext create]
  52.     scanmatch $cid $exp {append lines "File \"[file tail $f]\"; Line $matchInfo(linenum): $matchInfo(line)\r"}
  53.     set lines ""
  54.  
  55.     foreach f $files {
  56.         set fid [open $f]
  57.         scanfile $cid $fid
  58.         close $fid
  59.     }
  60.     scancontext delete $cid
  61.     return $lines
  62. }
  63.  
  64.